package com.yaorange.nongjt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.nongjt.domain.NjtSerialAuth;
import com.yaorange.nongjt.service.INjtSerialAuthService;
import com.yaorange.common.utils.poi.ExcelUtil;
import com.yaorange.common.core.page.TableDataInfo;

/**
 * 打印机认证情况Controller
 *
 * @author llx
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/nongjt/auth")
public class NjtSerialAuthController extends BaseController
{
    @Autowired
    private INjtSerialAuthService njtSerialAuthService;

    /**
     * 查询打印机认证情况列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtSerialAuth njtSerialAuth)
    {
        startPage();
        List<NjtSerialAuth> list = njtSerialAuthService.selectNjtSerialAuthList(njtSerialAuth);
        return getDataTable(list);
    }

    /**
     * 导出打印机认证情况列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:export')")
    @Log(title = "打印机认证情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtSerialAuth njtSerialAuth)
    {
        List<NjtSerialAuth> list = njtSerialAuthService.selectNjtSerialAuthList(njtSerialAuth);
        ExcelUtil<NjtSerialAuth> util = new ExcelUtil<NjtSerialAuth>(NjtSerialAuth.class);
        util.exportExcel(response, list, "打印机认证情况数据");
    }

    /**
     * 获取打印机认证情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(njtSerialAuthService.selectNjtSerialAuthById(id));
    }

    /**
     * 新增打印机认证情况
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:add')")
    @Log(title = "打印机认证情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtSerialAuth njtSerialAuth)
    {
        return toAjax(njtSerialAuthService.insertNjtSerialAuth(njtSerialAuth));
    }

    /**
     * 修改打印机认证情况
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:edit')")
    @Log(title = "打印机认证情况", businessType = BusinessType.UPDATE)
    @PutMapping("/certification") // 明确指定路径
    public AjaxResult updateCertification(@RequestBody NjtSerialAuth njtSerialAuth) {
        return toAjax(njtSerialAuthService.updateNjtSerialAuth(njtSerialAuth));
    }

    /**
     * 修改打印机使用状态
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:editUsageStatus')")
    @Log(title = "打印机使用状态", businessType = BusinessType.UPDATE)
    @PutMapping("/usageStatus") // 明确指定路径
    public AjaxResult updateUsageStatus(@RequestBody NjtSerialAuth njtSerialAuth) {
        if (njtSerialAuth.getUsageStatus() == null) {
            return error("使用状态不能为空");
        }
        return toAjax(njtSerialAuthService.updateNjtSerialAuthUsageStatus(njtSerialAuth));
    }



    /**
     * 删除打印机认证情况
     */
    @PreAuthorize("@ss.hasPermi('nongjt:auth:remove')")
    @Log(title = "打印机认证情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(njtSerialAuthService.deleteNjtSerialAuthByIds(ids));
    }
}
